package cpp.ece480.compteam;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class CustomerOrders extends Activity {

	public TextView heading;
	public TextView totalPrice;
	public TextView beveragePrice;
	public TextView breakfastPrice;
	public TextView lunchPrice;
	public TextView dinnerPrice;
	public TextView dessertPrice;
	public TextView beverageItem;
	public TextView breakfastItem;
	public TextView lunchItem;
	public TextView dinnerItem;
	public TextView dessertItem;

	public String customerPrice;
	public String bvItem;
	public String bkItem;
	public String lnItem;
	public String dnItem;
	public String dsItem;

	public String bvCost;
	public String bkCost;
	public String lnCost;
	public String dnCost;
	public String dsCost;
	public int tableNumber;
	public int customerNumber;
	public int tempPrice = 0;

	public boolean table1selected;
	public boolean table2selected;
	public boolean table3selected;
	public boolean table4selected;
	public boolean table5selected;
	public boolean table6selected;

	public boolean customer1selected;
	public boolean customer2selected;
	public boolean customer3selected;
	public boolean customer4selected;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.customerscreen);
		MySQL_AndroidInterface mySQLInterface = new MySQL_AndroidInterface();
		table1selected = ((GlobalVariable) this.getApplication()).getTable1();
		table2selected = ((GlobalVariable) this.getApplication()).getTable2();
		table3selected = ((GlobalVariable) this.getApplication()).getTable3();
		table4selected = ((GlobalVariable) this.getApplication()).getTable4();
		table5selected = ((GlobalVariable) this.getApplication()).getTable5();
		table6selected = ((GlobalVariable) this.getApplication()).getTable6();

		if (table1selected) {
			tableNumber = 1;
		} else if (table2selected) {
			tableNumber = 2;
		} else if (table3selected) {
			tableNumber = 3;
		} else if (table4selected) {
			tableNumber = 4;
		} else if (table5selected) {
			tableNumber = 5;
		} else if (table6selected) {
			tableNumber = 6;
		} else {
			tableNumber = 0;
		}

		customer1selected = ((GlobalVariable) this.getApplication())
				.getCustomer1();
		customer2selected = ((GlobalVariable) this.getApplication())
				.getCustomer2();
		customer3selected = ((GlobalVariable) this.getApplication())
				.getCustomer3();
		customer4selected = ((GlobalVariable) this.getApplication())
				.getCustomer4();

		if (customer1selected) {
			customerNumber = 1;
		} else if (customer2selected) {
			customerNumber = 2;
		} else if (customer3selected) {
			customerNumber = 3;
		} else if (customer4selected) {
			customerNumber = 4;
		} else {
			customerNumber = 0;
		}

		heading = (TextView) findViewById(R.id.heading);
		heading.setText("Table " + tableNumber + " Customer " + customerNumber
				+ " Orders");

		beverageItem = (TextView) findViewById(R.id.beverageItem);
		bvItem = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
				"beverages", "customerNum", String.valueOf(customerNumber),
				"TableNum", String.valueOf(tableNumber));
		beverageItem.setText(bvItem);
		beveragePrice = (TextView) findViewById(R.id.beveragePrice);
		if (bvItem.startsWith("C")) {
			bvItem = "Cappuccino";
		} else if (bvItem.startsWith("J")) {
			bvItem = "Juice";
		} else if (bvItem.startsWith("L")) {
			bvItem = "Lemonade";
		} else if (bvItem.startsWith("M")) {
			bvItem = "Milk";
		} 		
		bvCost = mySQLInterface.MySQL_READ3("10.0.2.2", "tables", "beverages",
				"Price", "Item", bvItem);
		beveragePrice.setText("$" + bvCost);
		if (bvCost.startsWith("2"))
			bvCost = "2";
		if (bvCost != null){
//		tempPrice = tempPrice + Integer.parseInt(bvCost);
		}
/*		
		breakfastItem = (TextView) findViewById(R.id.breakfastItem);
		bkItem = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
				"breakfast", "customerNum", String.valueOf(customerNumber),
				"TableNum", String.valueOf(tableNumber));
		breakfastItem.setText(bkItem);
		if (bvItem.startsWith("B")) {
			bkItem = "Burrito";
		} else if (bkItem.startsWith("O")) {
			bkItem = "Omlette";
		} else if (bkItem.startsWith("P")) {
			bkItem = "Pancakes";
		}
		bkCost = mySQLInterface.MySQL_READ3("10.0.2.2", "tables", "breakfast",
				"Price", "Item", bkItem);
		breakfastPrice = (TextView) findViewById(R.id.breakfastPrice);
		breakfastPrice.setText("$" + bkCost);
		if (bvCost != null){
//		tempPrice = tempPrice + Integer.parseInt(bkCost);
		}
		
		
		lunchItem = (TextView) findViewById(R.id.lunchItem);
		lnItem = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
				"lunch", "customerNum", String.valueOf(customerNumber),
				"TableNum", String.valueOf(tableNumber));
		lunchItem.setText(lnItem);
		if (lnItem.startsWith("B")) {
			lnItem = "Burger";
		} else if (lnItem.startsWith("Sal")) {
			lnItem = "Salad";
		} else if (lnItem.startsWith("San")) {
			lnItem = "Sandwich";
		}
		lnCost = mySQLInterface.MySQL_READ3("10.0.2.2", "tables", "lunch",
				"Price", "Item", lnItem);
		lunchPrice = (TextView) findViewById(R.id.lunchPrice);
		lunchPrice.setText("$" + lnCost);
		if (bvCost != null  || bvCost != "'"){
//		tempPrice = tempPrice + Integer.parseInt(lnCost);
		}

		dinnerItem = (TextView) findViewById(R.id.dinnerItem);
		dnItem = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
				"dinner", "customerNum", String.valueOf(customerNumber),
				"TableNum", String.valueOf(tableNumber));
		dinnerItem.setText(dnItem);
		if (dnItem.startsWith("C")) {
			dnItem = "Chicken";
		} else if (dnItem.startsWith("Sk")) {
			dnItem = "Skillet";
		} else if (dnItem.startsWith("Sp")) {
			dnItem = "Spaghetti";
		} else if (dnItem.startsWith("St")) {
			dnItem = "Steak";
		}
		dnCost = mySQLInterface.MySQL_READ3("10.0.2.2", "tables", "dinner",
				"Price", "Item", dnItem);
		dinnerPrice = (TextView) findViewById(R.id.dinnerPrice);
		dinnerPrice.setText("$" + dnCost);
		if (bvCost != null){
//		tempPrice = tempPrice + Integer.parseInt(dnCost);
		}

		dessertItem = (TextView) findViewById(R.id.dessertItem);
		dsItem = mySQLInterface.MySQL_READ2("10.0.2.2", "tables", "ordernum",
				"dessert", "customerNum", String.valueOf(customerNumber),
				"TableNum", String.valueOf(tableNumber));
		dessertItem.setText(dsItem);
		if (dsItem.startsWith("Ca")) {
			dsItem = "Cake";
		} else if (dsItem.startsWith("Ch")) {
			dsItem = "Cheesecake";
		} else if (dsItem.startsWith("S")) {
			dsItem = "Sundae";
		}
		dsCost = mySQLInterface.MySQL_READ3("10.0.2.2", "tables", "dessert",
				"Price", "Item", dsItem);
		dessertPrice = (TextView) findViewById(R.id.dessertPrice);
		dessertPrice.setText("$" + dsCost);
		if (bvCost != null){		
//			tempPrice = tempPrice + Integer.parseInt(dsCost);
		}
*/
		totalPrice = (TextView) findViewById(R.id.totalPrice);
		//customerPrice = String.valueOf(tempPrice);
		customerPrice = bvCost;
		mySQLInterface.MySQL_UPDATE2("10.0.2.2", "tables", "ordernum",
				"totalprice", customerPrice, "customerNum",
				String.valueOf(customerNumber), "tablenum",
				String.valueOf(tableNumber));
		totalPrice.setText("$" + customerPrice);

	}

	protected void onPause() {
		super.onPause();
	}

	protected void onResume() {
		super.onResume();
	}

	protected void onDestroy() {
		super.onDestroy();
	}

	public void launchSelectItems(View v) {
		Intent intent = new Intent(this, SelectItem.class);
		startActivity(intent);
	}

	public void launchCheckoutScreen(View v) {
		Intent intent = new Intent(this, Checkout.class);
		startActivity(intent);
	}

}
